<template>
	<view style="width: 100%; height: 100vh;">
		<!-- 搜索栏 -->
	<!-- 	<view style="width: 702rpx;height: 50rpx;border-radius: 25rpx;background-color: #F5F5F5; display: flex;align-items: center;margin-top: 30rpx;">
			<image mode="aspectFill" src="../../static/home/search.png" style="width: 34rpx;height: 34rpx;margin-left: 49rpx;"></image>
			<view style="width: 1px;height: 32rpx;background-color: #E0E0E0;margin-left: 28rpx;"></view>
			<input placeholder="搜索预约人 联系方式" placeholder-class="inputclass" confirm-type="search" style="margin-left: 31rpx;font-size: 24rpx;" />
		</view> -->
	
		
		<scroll-view v-if="group_id == 1" :enable-flex="true" :show-scrollbar="false" @scrolltolower="lower" :scroll-y="true" style="width: 100%; display: flex;flex-direction: column; align-items: center;flex: auto; ">
			<view v-for="(item,index) in stafforder" :key="index" style="width: 100%; margin-top: 19rpx;display: flex;flex-direction: column;justify-content: center;align-items: center;"
			>
				<view style="width: 100%;height: 10rpx;background-color: #F7F8FF;"></view>
				<view style="width: 702rpx; display: flex;flex-direction: column;justify-content: center;align-items: center;margin-top: 19rpx;">
					<text style="font-size: 24rpx;color: #333333;align-self: flex-end;" >
						订单号：<text>{{item.order_sn}}</text>
					</text>
					<view style="width: 100%;height: 1px;background-color: #F7F8FF;margin-top: 20rpx;"></view>
					<view style="width: 702rpx; display: flex;justify-content: space-between;align-items: center;margin-top: 19rpx;"
					>
						<view class="order_show show_a">
							<text>预约时间:</text>
							<text>预约人:</text>
							<text>联系方式:</text>
							<text>预约类型:</text>
						</view>
						<view class="order_show show_b">
							<text>{{item.yuyueshijian}}</text>
							<text>{{item.consignee}}</text>
							<text>{{item.phone}}</text>
							<text>{{item.item[0].goods_title}}</text>
						</view>
					</view>
					<view style="width: 100%;height: 1px;background-color: #F7F8FF;margin-top: 20rpx;"></view>
					<view style="align-self: flex-end;display: flex;justify-content: center;align-items: center;font-size: 24rpx;color: #FFFFFF;margin-top: 19rpx;">
						<view style="width: 150rpx;height: 60rpx;background-color: #F07203;text-align: center;line-height: 60rpx;" @click="cancel(item)" v-show="type === 'nopay'">取消订单</view>
					</view>
				</view>
			</view>
			<text style="height: 50rpx;margin-top: 20rpx;font-size: 24rpx;color: #eeeeee;">加载数据</text>

		</scroll-view>


		<scroll-view v-else :enable-flex="true" :show-scrollbar="false" @scrolltolower="lower" :scroll-y="true" style="width: 100%; display: flex;flex-direction: column; align-items: center;flex: auto;">
			<view v-for="(item,index) in staffOrders" :key="index" style="width: 100%; margin-top: 19rpx;display: flex;flex-direction: column;justify-content: center;align-items: center;"
			>
				<view style="width: 100%;height: 10rpx;background-color: #F7F8FF;"></view>
				<view style="width: 702rpx; display: flex;flex-direction: column;justify-content: center;align-items: center;margin-top: 19rpx;">
					<text style="font-size: 24rpx;color: #333333;align-self: flex-end;" >
						订单号：{{item.order_sn}}
					</text>
					<view style="width: 100%;height: 1px;background-color: #F7F8FF;margin-top: 20rpx;"></view>
					<view style="width: 702rpx; display: flex;justify-content: space-between;align-items: center;margin-top: 19rpx;"
					>
						<view class="order_show show_a">
							<text>预约时间:</text>
							<text>预约人:</text>
							<text>联系方式:</text>
							<text>预约类型:</text>
						</view>
						<view class="order_show show_b">
							<text>{{item.yuyueshijian}}</text>
							<text>{{item.consignee}}</text>
							<text>{{item.phone}}</text>
							<text>{{item.item[0].goods_title}}</text>
						</view>
					</view>
					<view style="width: 100%;height: 1px;background-color: #F7F8FF;margin-top: 20rpx;"></view>
					<view style="align-self: flex-end;display: flex;justify-content: center;align-items: center;font-size: 24rpx;color: #FFFFFF;margin-top: 19rpx;">
						<view style="width: 150rpx;height: 60rpx;background-color: #4B9EFF;text-align: center;line-height: 60rpx;margin-right: 27rpx;" @click="GO('writeOff',item)" v-show="type === 'nopay' ">立即核销</view>
						<view style="width: 150rpx;height: 60rpx;background-color: #F07203;text-align: center;line-height: 60rpx;" @click="cancel(item)" v-show="type === 'nopay'">取消订单</view>
					</view>
				</view>
			</view>
			<text style="height: 50rpx;margin-top: 20rpx;font-size: 24rpx;color: #eeeeee;">加载数据</text>
		
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				group_id:'', //获取用户权限，控制核销开关
				type:'',
				stafforder:[],//普通用户
				staffOrders:[],//员工
				orderList: [{
						orderNumber: 'ABC123568974512385462892563245',
						orderContext: [{
								title: '预约时间：',
								context: '2021-01-15 14:38:25'
							},
							{
								title: '预约人：',
								context: '不知道你叫啥'
							},
							{
								title: '联系方式：',
								context: '13622020022'
							},
							{
								title: '预约类型：',
								context: '服务/洗车'
							}
						]
					},
				],
				page: 1

			}
		},
		onLoad() {
			this.group_id = uni.getStorageSync('group_id') //进页面获取员工但是用户身份
			console.log('this.group_id :员工身份确认>> ', this.group_id);
			this.type = this.$Route.query.type; //我的页面携带的参数，决定订单状态
			console.log('this.type ===========点击功能:>> ', this.type);
			//this.group_id = this.$Route.query.group_id; //我的页面携带的参数，决定订单状态
			
			console.log("this.type: ",this.type);
			console.log(": type",this.type);
			// this.staffOrder();
			// this.employees();
		},
		onShow() {
			this.staffOrder();
		},
		onReachBottom() {
			this.page++
			this.staffOrder()
			console.log("滑动到了页面底部")
		},
		methods: {
			GO(type,item){
				// this.staffOrder();
				this.$Router.push({
					name:type,
					params:{
						item:item
					}
				})
			},
			async cancel(item){
				let res;
				try{
					res = await this.$request.post('addons/shopro/order/cancel',{
						data:{
							id:item.id
						}
					})
				}catch(e) {
					console.log('e :>> ', e);
					return uni.showToast({
						title:'网络链接失败',
						icon:'icon'
					})
				}
				this.staffOrder();
				// this.employees();
				this.$forceUpdate();
			},
			// lower(){
			// 	this.page++
			// 	this.staffOrder()
			// 	console.log("滑动到了页面底部")
			// },
			// 用户订单展示 非员工
			async staffOrder() {
				let res;
				try{
					 res = await this.$request.get('addons/shopro/order/index',{
						data:{
							type: this.type,
							page: this.page
						}
					})
				}catch(e){
					console.log("e: ",e);
					//TODO handle the exception
					return uni.showToast({
						title:'网络连接失败',
						icon:'none'
					});
				}
				let group_id = uni.getStorageSync('group_id');
				if(group_id == 2) {
					// 如果是员工单，调取接口
					this.employees();
				}
				// this.stafforder = res.data.data.data;
				this.stafforder = [...this.stafforder,...res.data.data.data]
				this.$forceUpdate();
				console.log("this.stafforder: ",this.stafforder);
				console.log("res: ",res);
			},
			// 员工订单
			async employees() {
				let res;
				try{
					 res = await this.$request.post('addons/shopro/staff/order',{
						data:{
							type:this.type,
							page:1
						}
					})
				}catch(e){
					console.log("e: ",e);
					//TODO handle the exception
					return uni.showToast({
						title:'网络连接失败',
						icon:'none'
					});
				}
				this.staffOrders = res.data.data.data;
				// this.staffOrder();
				this.$forceUpdate();
				console.log("this.stafforder: ",this.stafforder);
				console.log("res: ",res);
			},
		}
	}
</script>

<style lang="scss" scoped>
.order_show {
	    display: flex;
	    flex: 1;
	    flex-direction: column;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		&:first-child {
			color: #666;
		}
		&:last-child {
			color: #333;
		}
		>text {
			line-height: 1.6;
		}
}
</style>
